setTransferBoxVisible(false)
smooth=getTickCount()
screen=Vector2(guiGetScreenSize())


local zoom = 1
local fh = 1920
if screen.x < fh then
  zoom = math.min(2,fh/screen.x)
end

data={}
data[localPlayer]={}
data[localPlayer]["rot"]=0
data[localPlayer]["total"]=0
data[localPlayer]["actually"]=0
data[localPlayer]["percent"]=0
data[localPlayer]["znak"]="kB"
data[localPlayer]["znak2"]="kB"
data[localPlayer]["count"]=1
data[localPlayer]["alpha"]=255

data[localPlayer]["font"]={}
data[localPlayer]["font"][1]=dxCreateFont("font.ttf",(16/1920)*screen.x)
data[localPlayer]["font"][2]=dxCreateFont("font.ttf",(12/1920)*screen.x)


images={
    {"1.jpg","2.jpg","3.jpg","4.jpg"}
}

pos={
    ["rec"]={(0/1920)*screen.x, (0/1080)*screen.y, (1920/1920)*screen.x, (1080/1080)*screen.y},
    ["bg"]={(0/1920)*screen.x, (0/1080)*screen.y, (1920/1920)*screen.x, (1080/1080)*screen.y},
    ["load"]={(14/1920)*screen.x, (1000/1080)*screen.y, 40/zoom, 40/zoom},
    ["txt_info"]={(70/1920)*screen.x, (983/1080)*screen.y, (376/1920)*screen.x, (1021/1080)*screen.y},
    ["txt_download"]={(70/1920)*screen.x, (1050/1080)*screen.y, (376/1920)*screen.x, (1021/1080)*screen.y}
}



function przejscie()
    if wygaszenie then
        if data[localPlayer]["alpha"]>0 then
            data[localPlayer]["alpha"]=data[localPlayer]["alpha"]-1
        elseif data[localPlayer]["alpha"]<=0 then
            wygaszenie=false
            odpalanie=true
            data[localPlayer]["count"]=data[localPlayer]["count"]+1
            if data[localPlayer]["count"]>#images[1] then
                data[localPlayer]["count"]=1
            end
        end
    elseif odpalanie then
        if data[localPlayer]["alpha"]<255 then
            data[localPlayer]["alpha"]=data[localPlayer]["alpha"]+1
            outputChatBox(data[localPlayer]["alpha"])
        elseif data[localPlayer]["alpha"]==255 then
            smooth=getTickCount()
            removeEventHandler("onClientRender",root,przejscie)
            odpalanie=false
        end
    end
end

function render()
    local tick3=getTickCount()
    if tick3-smooth>=9500 then
        smooth=getTickCount()
        addEventHandler("onClientRender",root,przejscie)
        wygaszenie=true
    end
    local sin=math.sin(getTickCount()/2000)*40
    dxDrawRectangle(pos["rec"][1],pos["rec"][2],pos["rec"][3],pos["rec"][4], tocolor(0, 0, 0, 255), false)
    dxDrawImage(pos["bg"][1]+sin,pos["bg"][2],pos["bg"][3],pos["bg"][4], "img/"..images[1][tonumber(data[localPlayer]["count"])], 0, 0, 0, tocolor(255, 255, 255, data[localPlayer]["alpha"]), false)
    dxDrawImage(pos["load"][1],pos["load"][2],pos["load"][3],pos["load"][4], "img/load.png", getTickCount()/10, 0, 0, tocolor(255, 255, 255, 255), true)
    dxDrawText("Pobieram dla Ciebie zasoby serwera...",pos["txt_info"][1],pos["txt_info"][2],pos["txt_info"][3],pos["txt_info"][4] , tocolor(255, 255, 255, 255), 1.00,data[localPlayer]["font"][1] , "left", "center", false, false, true, false, false)
    dxDrawText(math.floor(data[localPlayer]["actually"])..""..data[localPlayer]["znak"].."/"..math.floor(data[localPlayer]["total"])..""..data[localPlayer]["znak2"].." ("..data[localPlayer]["percent"].."%)",pos["txt_download"][1],pos["txt_download"][2],pos["txt_download"][3],pos["txt_download"][4] , tocolor(255, 255, 255, 255), 1.00,data[localPlayer]["font"][2] , "left", "center", false, false, true, false, false)
end







function downloadComplete()
    if not isTransferBoxActive() then
        removeEventHandler("onClientRender", root, render)
        if wygaszenie or odpalanie then
            removeEventHandler("onClientRender",root,przejscie)
        end
        stopSound(sound)
        showChat(true)
    else
        setTimer(downloadComplete, 1000, 1)
    end
end


addEventHandler("onClientResourceStart", resourceRoot, function()
    addEventHandler("onClientRender", root, render)
    sound=playSound("sound.mp3",true)
    setSoundVolume(sound,0.5)
    setTimer(downloadComplete, 1000, 1)
    showChat(false)
end)







addEventHandler("onClientTransferBoxProgressChange", root, function(actually, total)
    data[localPlayer]["percent"]=math.floor((actually / total) * 100)
    if (actually/1024)/1024<1 then
        data[localPlayer]["actually"]=actually/1024
        data[localPlayer]["znak"]="kB"
    elseif (actually/1024)/1024>=1 then
        data[localPlayer]["actually"]=(actually/1024)/1024
        data[localPlayer]["znak"]="MB"
    end

    if (total/1024)/1024<1 then
        data[localPlayer]["total"]=total/1024
        data[localPlayer]["znak2"]="kB"
    elseif (total/1024)/1024>=1 then
        data[localPlayer]["total"]=(total/1024)/1024
        data[localPlayer]["znak2"]="MB"
    end
end)
